package cn.lavenliu.hellospring;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LoggingController {
    private static final Logger logger = LoggerFactory.getLogger(DemoApplication.class);

    public Integer a;

    @RequestMapping(value="/helloInfo", method=RequestMethod.GET)
	public String helloWorldInfo() {
		logger.info("A INFO message");
		return new String("Hello Spring Info");
	}

    @RequestMapping(value="/helloWarn", method=RequestMethod.GET)
	public String helloWorldWarn() {
		logger.warn("A WARN message");
		return new String("Hello Spring Warning");
	}

    @RequestMapping(value="/helloError", method=RequestMethod.GET)
	public String helloWorldError() {
		logger.error("A ERROR message");
		return new String("Hello Spring Error");
	}

    @RequestMapping(value="/helloException", method=RequestMethod.GET)
    public void helloWorldException() {
        try {
            a = 1 / 0;
        } catch (ArithmeticException ex) {
            logger.error("Oh, Exception is here", ex);
            // e.printStackTrace();
        }
    }
	
}
